# 对模型参数进行对比
import torch

mapl = torch.device("cpu")
ckpt1 = torch.load("../deep/checkpoint/ckpt.t7",map_location=mapl)
ckpt2 = torch.load("../deep/checkpoint/ckpt_class11_train200_freez150.t7",map_location=mapl)
net_dict1 = ckpt1['net_dict']
net_dict2 = ckpt2['net_dict']
# print(net_dict1.keys())
# print(net_dict2.keys())
keys1 = list(net_dict1.keys())
keys2 = list(net_dict2.keys())
print(keys1 == keys2)
same = set()
notsame = set()
for key in keys1:
    if net_dict1[key].equal(net_dict2[key]):
        same.add(key)
    else:
        notsame.add(key)

l1 = net_dict1['conv.1.num_batches_tracked']
l2 = net_dict2['conv.1.num_batches_tracked']
print(l1)
print(l2)

# print(same & notsame)
# print(same)
# print(notsame)

# print(len(same))
# print(len(notsame))

# 'layer4.0.bn2.running_mean'

# 没变化的
# {'layer1.0.bn2.weight', 'layer2.1.bn1.bias', 'layer3.0.bn1.bias', 'layer2.0.bn2.bias', 'layer1.1.bn1.bias', 'layer2.0.bn1.weight', 'layer2.0.downsample.1.weight', 'layer4.1.bn1.weight', 'layer2.1.conv2.weight', 'layer1.1.bn2.bias', 'layer4.0.bn2.bias', 'layer1.0.bn1.bias', 'layer4.0.conv2.weight', 'layer3.1.conv1.weight', 'layer4.0.bn1.weight', 'layer3.0.downsample.1.bias', 'conv.0.bias', 'layer2.0.bn2.weight', 'layer1.0.bn2.bias', 'layer1.0.bn1.weight', 'layer3.0.downsample.1.weight', 'layer4.0.conv1.weight', 'layer4.1.conv2.weight', 'layer1.0.conv1.weight', 'layer3.1.bn1.weight', 'layer3.1.conv2.weight', 'layer4.0.downsample.1.bias', 'layer2.1.bn1.weight', 'layer1.1.bn2.weight', 'layer4.0.bn2.weight', 'layer3.0.bn2.weight', 'layer2.0.downsample.0.weight', 'layer2.0.conv1.weight', 'layer2.0.conv2.weight', 'layer3.0.conv2.weight', 'layer3.0.bn1.weight', 'classifier.1.bias', 'layer2.1.bn2.bias', 'conv.1.bias', 'layer4.1.bn1.bias', 'conv.0.weight', 'layer3.0.downsample.0.weight', 'classifier.1.weight', 'layer1.1.conv2.weight', 'layer1.1.conv1.weight', 'layer4.1.bn2.weight', 'layer3.1.bn2.bias', 'layer3.0.bn2.bias', 'layer3.1.bn1.bias', 'layer3.0.conv1.weight', 'layer4.0.downsample.0.weight', 'classifier.0.bias', 'conv.1.weight', 'layer4.1.conv1.weight', 'layer4.1.bn2.bias', 'classifier.0.weight', 'layer2.0.downsample.1.bias', 'layer2.0.bn1.bias', 'layer1.0.conv2.weight', 'layer2.1.conv1.weight', 'layer2.1.bn2.weight', 'layer4.0.bn1.bias', 'layer4.0.downsample.1.weight', 'layer3.1.bn2.weight', 'layer1.1.bn1.weight'}  

# 变化的
# {'layer4.0.bn2.running_mean', 'conv.1.num_batches_tracked', 'layer3.0.bn2.running_var', 'layer3.1.bn2.running_var', 'layer1.1.bn1.num_batches_tracked', 'layer2.1.bn2.num_batches_tracked', 'layer1.1.bn1.running_var', 'classifier.4.bias', 'classifier.4.weight', 'layer3.0.bn1.running_var', 'layer3.0.bn1.running_mean', 'layer3.1.bn1.num_batches_tracked', 'layer3.0.downsample.1.num_batches_tracked', 'layer2.0.bn1.num_batches_tracked', 'classifier.1.num_batches_tracked', 'layer4.1.bn2.num_batches_tracked', 'layer4.0.bn1.running_mean', 'conv.1.running_mean', 'layer4.0.bn2.num_batches_tracked', 'layer3.1.bn1.running_var', 'layer1.0.bn1.num_batches_tracked', 'layer1.0.bn2.num_batches_tracked', 'layer2.1.bn1.num_batches_tracked', 'layer2.0.bn1.running_var', 'layer4.0.downsample.1.running_mean', 'layer4.0.downsample.1.running_var', 'layer2.1.bn2.running_var', 'layer2.1.bn1.running_var', 'layer2.0.downsample.1.running_mean', 'layer3.0.bn2.num_batches_tracked', 'layer4.0.bn1.running_var', 'layer3.0.downsample.1.running_var', 'layer3.1.bn1.running_mean', 'layer1.0.bn1.running_var', 'layer2.0.bn1.running_mean', 'layer4.0.bn1.num_batches_tracked', 'layer1.1.bn2.num_batches_tracked', 'layer1.0.bn1.running_mean', 'layer4.0.downsample.1.num_batches_tracked', 'layer3.0.bn2.running_mean', 'layer3.0.downsample.1.running_mean', 'layer4.1.bn1.running_var', 'layer4.1.bn2.running_var', 'layer3.1.bn2.num_batches_tracked', 'layer3.0.bn1.num_batches_tracked', 'layer1.0.bn2.running_var', 'layer2.1.bn2.running_mean', 'layer2.0.downsample.1.running_var', 'layer1.1.bn1.running_mean', 'layer2.0.bn2.running_var', 'layer4.1.bn2.running_mean', 'layer2.0.bn2.num_batches_tracked', 'classifier.1.running_var', 'layer2.0.bn2.running_mean', 'layer4.0.bn2.running_var', 'layer2.0.downsample.1.num_batches_tracked', 'conv.1.running_var', 'layer2.1.bn1.running_mean', 'layer4.1.bn1.running_mean', 'classifier.1.running_mean', 'layer3.1.bn2.running_mean', 'layer4.1.bn1.num_batches_tracked', 'layer1.1.bn2.running_mean', 'layer1.0.bn2.running_mean', 'layer1.1.bn2.running_var'}

